<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>xy2svmlight.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_name>xy2svmlight</span>(<span class=defun_in>data,file_name</span>)<br>
<span class=h1>%&nbsp;XY2SVMLIGHT&nbsp;Converts&nbsp;data&nbsp;set&nbsp;to&nbsp;SVM^{light}&nbsp;format.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;xy2svmlight(data,file_name).</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;function&nbsp;saves&nbsp;training&nbsp;data&nbsp;to&nbsp;text&nbsp;file&nbsp;required</span><br>
<span class=help>%&nbsp;&nbsp;by&nbsp;the&nbsp;SVM^{light}&nbsp;software.&nbsp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;data.X&nbsp;[dim&nbsp;x&nbsp;num_data]&nbsp;training&nbsp;data&nbsp;stored&nbsp;as&nbsp;column&nbsp;vectors.</span><br>
<span class=help>%&nbsp;&nbsp;data.y&nbsp;[1&nbsp;x&nbsp;num_data]&nbsp;labels&nbsp;of&nbsp;traning&nbsp;data;&nbsp;possible&nbsp;values&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;are&nbsp;1&nbsp;(first&nbsp;class)&nbsp;and&nbsp;2&nbsp;(second&nbsp;class).</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;Text&nbsp;file&nbsp;'file_name'&nbsp;in&nbsp;SVM^{Light}&nbsp;format.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;SVMLIGHT.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;14-Jan-2003,&nbsp;VF</span><br>
<span class=help1>%&nbsp;30-apr-2001,&nbsp;V.&nbsp;Franc,&nbsp;created</span><br>
<br>
<hr>
fid&nbsp;=&nbsp;fopen(&nbsp;file_name,&nbsp;<span class=quotes>'w+'</span>);<br>
<br>
dim=size(data.X,1);<br>
num_data=size(data.X,2);<br>
<br>
txt&nbsp;=&nbsp;zeros(1,2*dim);<br>
inx1&nbsp;=&nbsp;1:2:2*dim;<br>
txt(inx1)&nbsp;=&nbsp;1:dim;<br>
inx2&nbsp;=&nbsp;2:2:2*dim;<br>
<br>
<span class=keyword>for</span>&nbsp;i=1:num_data,<br>
<br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;data.y(i)&nbsp;==&nbsp;1,&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=io>fprintf</span>(fid,<span class=quotes>'+1&nbsp;'</span>);&nbsp;<br>
&nbsp;&nbsp;<span class=keyword>elseif</span>&nbsp;data.y(i)&nbsp;==&nbsp;2,<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=io>fprintf</span>(fid,<span class=quotes>'-1&nbsp;'</span>);&nbsp;<br>
&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class=io>fprintf</span>(fid,<span class=quotes>'0&nbsp;'</span>);&nbsp;<br>
&nbsp;&nbsp;<span class=keyword>end</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;txt(inx2)&nbsp;=&nbsp;data.X(:,i);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<span class=io>fprintf</span>(&nbsp;fid,&nbsp;<span class=quotes>'%d:%f&nbsp;'</span>,&nbsp;txt&nbsp;);<br>
&nbsp;&nbsp;<span class=io>fprintf</span>(fid,<span class=quotes>'\n'</span>);<br>
<span class=keyword>end</span><br>
<br>
fclose(fid);<br>
<br>
<span class=jump>return</span>;<br>
</code>
